package main

import (
	"bytes"
	"fmt"
	"log"
	"os/exec"
)
func main() {
	data := getGPUData()
	fmt.Println(data)
}

func runCommand(cmd string) (string, error) {
	var out bytes.Buffer
	var stderr bytes.Buffer
	cmdObj := exec.Command("bash", "-c", cmd)
	cmdObj.Stdout = &out
	cmdObj.Stderr = &stderr
	err := cmdObj.Run()
	if err != nil {
		log.Println("命令执行出错: ", cmd, err)
		return "", err
	}
	return out.String(), nil
}

func getGPUData() string {
	cmd := "curl -sL http://10.96.92.182:9400/metrics | grep ffmpeg-gpu-pod-1"
	output, err := runCommand(cmd)
	if err != nil {
		return ""
	}
	// rate, err := strconv.ParseFloat(strings.Split(output, "\n")[0], 64)
	// if err != nil {
	// 	return 0
	// }
	return output
}